package hudson.plugins.aspen;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import hudson.model.AbstractBuild;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;

import org.kohsuke.stapler.StaplerProxy;

public class AspenBuildAction implements HealthReportingAction, StaplerProxy, Serializable {

	private static final long serialVersionUID = 6797304293393247632L;
	
	public final AbstractBuild<?,?> owner;
	FeatureSupportReport featureSupport;
	
	public AspenBuildAction(AbstractBuild<?, ?> build){
		owner = build;
	}
	
	public AbstractBuild<?,?> getBuild() {
        return owner;
    }
	
	public HealthReport getBuildHealth() {
		return new HealthReport(0, "");
	}

	public String getDisplayName() {
		return "Aspen Report";
	}

	public String getIconFileName() {
		return "graph.gif";
	}

	public String getUrlName() {
		return "aspen";
	}

	public Object getTarget() {
		return this;
	}

	public FeatureLogVarianceReport diff(String feature){
		return null;
	}
	
	public void setFeatureSupport(FeatureSupportReport featureSupport) {
		this.featureSupport = featureSupport;
	}
	
	public FeatureSupportReport getFeatureSupport(){
		return featureSupport;
	}
	
	public void addLogVariance(String name, Map<String, File> platformLogs){
		// for each file check compare contents.
		// store every distinct result iff all files are NOT identical
		// (ie. never store a single file)
		
	}
	
}

class LogVariance {
	String testName;
	Map<String/*log*/, List<String>/*platforms*/> logs;
	
	public LogVariance(String testName){
		this.testName = testName;
		logs = new HashMap<String, List<String>>();
	}
	
	public void add(String platform, String log){
		List<String> platforms = logs.get(log);
		if(platforms == null){
			logs.put(log, new ArrayList<String>());
			logs.get(log).add(platform);
		} else {
			platforms.add(platform);
		}
	}
}
